/*
  包含应用的所有接口的接口请求函数
    函数内部调用 ajax 函数发送请求
    函数返回的是 Promise 对象
*/
import ajax from './ajax'
import mockAjax from './mockAjax'

// 首页三级分类
export function reqCategoryList () {
  // return ajax.get('/product/getBaseCategoryList')
  return ajax({
    url: '/product/getBaseCategoryList',
    method: 'GET'
  })
}

// 获取首页广告轮播列表
export const reqBannerList = () => ajax('/cms/banner')

// mock 接口函数
export const reqRecommends = () => mockAjax('/recommends')
export const reqFloors = () => mockAjax('/floors')

// 搜索分页列表
export const reqSearch = (searchParams) => ajax.post('/list', searchParams)

// 获取详情数据
export const reqDetailInfo = (skuId) => {
  return ajax({
    url: `/item/${skuId}`,
    method: 'GET'
  })
}

// 添加购物车(修改购物车的商品数量)
export const reqAddOrUpdateCart = (skuId, skuNum) => {
  return ajax({
    url: `/cart/addToCart/${skuId}/${skuNum}`,
    method: 'POST'
  })
}

// 获取购物车列表
export const reqCartList = () => {
  return ajax({
    url: '/cart/cartList',
    method: 'GET'
  })
}

// 修改购物车的选中状态
export const reqUpdateCartChecked = (skuId, isChecked) => {
  return ajax({
    url: `/cart/checkCart/${skuId}/${isChecked}`,
    method: 'GET'
  })
}

// 删除购物车(单个)
export const reqDeleteCart = (skuId) => {
  return ajax({
    url: `/cart/deleteCart/${skuId}`,
    method: 'DELETE'
  })
}

// 用户注册
export const reqUserRegister = (userInfo) => {
  return ajax({
    url: '/user/passport/register',
    method: 'POST',
    data: userInfo
  })
}

// 用户登录
export const reqUserLogin = (userInfo) => {
  return ajax({
    url: '/user/passport/login',
    method: 'POST',
    data: userInfo
  })
}

// 根据 token 获取用户信息
export const reqUserInfo = () => {
  return ajax({
    url: '/user/passport/auth/getUserInfo',
    method: 'GET'
  })
}

// 退出登录
export const reqUserLogout = () => {
  return ajax({
    url: '/user/passport/logout',
    method: 'GET'
  })
}

// 获取交易页面信息
export const reqTradeInfo = () => {
  return ajax({
    url: '/order/auth/trade',
    method: 'GET'
  })
}

// 请求提交订单(真正创建订单)
export const reqSubmitOrder = (tradeNo, tradeData) => {
  return ajax({
    url: `/order/auth/submitOrder?tradeNo=${tradeNo}`,
    method: 'POST',
    data: tradeData
  })
}

// 获取支付信息
export const reqPayInfo = (orderId) => {
  return ajax({
    url: `/payment/weixin/createNative/${orderId}`,
    method: 'GET'
  })
}

// 查询订单支付状态
export const reqPayStatus = (orderId) => {
  return ajax({
    url: `/payment/weixin/queryPayStatus/${orderId}`,
    method: 'GET'
  })
}

// 请求获取我的订单列表(分页)
export const reqMyOrderInfo = (page, limit) => {
  return ajax({
    url: `/order/auth/${page}/${limit}`,
    method: 'GET'
  })
}